package com.tcoiss.common.mq.message;

import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * @author xuxueli 2016-08-28 14:05:23
 */
@Data
public class MqMessageDto implements Serializable {
	private static final long serialVersionUID = 42L;

	private long id;				// 消息ID,
	private String topic;			// 消息主题
	private String group;			// 消息分组, 分组一致时消息仅消费一次；存在多个分组时，多个分组时【广播消费】；
	private String data;			// 消息数据
	private String status;			// 消息状态, @sae MqMessageStatus
	private int retryCount;			// 重试次数, 执行失败且大于0时生效，每重试一次减一；
	private long shardingId;		// 分片ID, 大于0时启用，否则使用消息ID；消费者通过该参数进行消息分片消费；分片ID不一致时分片【并发消费】、一致时【串行消费】；
	private int timeout;			// 超时时间，单位秒；大于0时生效，处于锁定运行状态且运行超时时，将主动标记运行失败；
	private Date effectTime;		// 生效时间, new Date()立即执行, 否则在生效时间点之后开始执行;
	private Date addTime;			// 创建时间
	private String log;				// 流转日志


	public MqMessageDto() {
	}

	public MqMessageDto(String topic, String data) {
		this.topic = topic;
		this.data = data;
	}

	public MqMessageDto(String topic, String data, Date effectTime) {
		this.topic = topic;
		this.data = data;
		this.effectTime = effectTime;
	}

	public MqMessageDto(String topic, String data, long shardingId) {
		this.topic = topic;
		this.data = data;
		this.shardingId = shardingId;
	}

	// for clone
	public MqMessageDto(MqMessageDto mqMessage) {
		this.id = mqMessage.id;
		this.topic = mqMessage.topic;
		this.group = mqMessage.group;
		this.data = mqMessage.data;
		this.status = mqMessage.status;
		this.retryCount = mqMessage.retryCount;
		this.shardingId = mqMessage.shardingId;
		this.timeout = mqMessage.timeout;
		this.effectTime = mqMessage.effectTime;
		this.addTime = mqMessage.addTime;
		this.log = mqMessage.log;
	}

	@Override
	public String toString() {
		return "MqMessage{" +
				"id=" + id +
				", topic='" + topic + '\'' +
				", group='" + group + '\'' +
				", data='" + data + '\'' +
				", status='" + status + '\'' +
				", retryCount=" + retryCount +
				", shardingId=" + shardingId +
				", timeout=" + timeout +
				", effectTime=" + effectTime +
				", addTime=" + addTime +
				", log='" + log + '\'' +
				'}';
	}

}